// The Swift Programming Language
// https://docs.swift.org/swift-book

import Foundation

@available(macOS 11,*)
@available(iOS 13.0.0, *)
@globalActor public actor Status: GlobalActor,ObservableObject{
    //@MainActor public actor Status: GlobalActor,ObservableObject{
    public static var shared: Status = Status()
    
    public typealias ActorType = Status
    
    public enum PlayStatus: String, CaseIterable{
        case playing
        case stop
        case pause
    }
    
    @Published public var playStatus: PlayStatus = .stop
    
    
    func updatePlayStatus(status: PlayStatus){
        
        self.playStatus = status
    }
    
    
}
@available(macOS 11,*)
@available(iOS 13.0.0, *)
public actor MyMainStatus: ObservableObject{
    public static var shared: MyMainStatus = MyMainStatus()
    
    //    public typealias ActorType = Status
    
    
    public enum PlayStatus: String, CaseIterable{
        case playing
        case stop
        case pause
    }
    
    @MainActor
    @Published public var playStatus: PlayStatus = .stop
    
    @MainActor
    func updatePlayStatus(status: PlayStatus){
        
        self.playStatus = status
    }
    
//
//    func update(status: PlayStatus) async{
//        
//        self.up
//    }
//    
    
    
    
}

@available(macOS 11,*)
@available(iOS 13.0, *)
@MainActor
public class ViewModel: ObservableObject{
    @Published var status: MyMainStatus.PlayStatus
    @Published var video: Int
    var actor: MyMainStatus = MyMainStatus.shared
    
    public init(){
        self.status = .stop
        self.video = 0
    }
    
    public func addVideo() async {
        self.video += 1
    }
    public func delVideo() async {
        self.video -= 1
    }
    
    
    public func play() async{
        
        
         actor.updatePlayStatus(status: MyMainStatus.PlayStatus.playing)
        
    }
    
    public func stop() async{
         actor.updatePlayStatus(status: MyMainStatus.PlayStatus.stop)
    }
    public func pause() async{
         actor.updatePlayStatus(status: MyMainStatus.PlayStatus.pause)
    }
}
